package com.atguigu.sort;


import com.atguigu.utils.ArrayGenerator;
import com.atguigu.utils.SortingHelper;
import org.junit.Test;

import java.util.Arrays;

public class SelectionSortTest {

    /**
     * 十万数据进行排序：9s
     */
    @Test
    public void test1(){
        int n=100000;
        Integer[] integers = ArrayGenerator.generateRandomArray(n, n);
        long startTime = System.currentTimeMillis();
        SelectionSort.Sort(integers);
        long endTime = System.currentTimeMillis();
        System.out.println((endTime-startTime)/1000.0+" s");
        if(!SortingHelper.isSorted(integers)){
            throw new RuntimeException("SelectionSort failed!");
        }
    }
    @Test
    public void test2() {
        int n=100000;
        Integer[] integers = ArrayGenerator.generateRandomArray(n, n);
        String path="com.atguigu.sort.SelectionSort";
        SortingHelper.sortTest(path,integers);
    }
    @Test
    public void test3(){
        int[]arr={19,89,67,23,67,347,89,100};
        InsertSort(arr);
        System.out.println(Arrays.toString(arr));
    }
    public void InsertSort(int[]arr){
        for(int i=0;i<arr.length;i++){
            for(int j=i;j-1>0;j--){
                if(arr[j-1]>arr[j]){
                    swap(arr,j,j-1);
                }else{
                    break;
                }
            }
        }
    }

    private void swap(int[] arr, int j, int i) {
        int temp=arr[j];
        arr[j]=arr[i];
        arr[i]=temp;
    }
}
